package com.owulia.leetcode.num.stack;

public class ValidateStackSequences {

    public static boolean validateStackSequences(int[] pushed, int[] popped) {
        int[] stack = new int[popped.length];
        int index = 0;
        for (int i = 0, j = 0; i < stack.length; i++) {
            stack[index] = pushed[i];
            while (index >= 0 && stack[index] == popped[j]) {
                j++;
                index--;
            }
            index++;
        }
        return index == 0;
    }

    public static void main(String[] args) {
        int[] pushed = {1, 2, 3, 4, 5}, popped = {4, 5, 3, 1, 2};
        System.out.print(validateStackSequences(pushed, popped));
    }




}
